<%--
  Created by IntelliJ IDEA.
  User: 郑自航
  Date: 2018/7/9
  Time: 14:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MerchQrcode</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="stylesheet" href="${basePath}/layui/css/layui.css">
    <script type="text/javascript" src="${basePath}/js/plugin/jquery-2.1.0.min.js"></script>
    <script type="text/javascript" src="${basePath}/js/plugin/jquery.i18n.properties.min.js"></script>
    <script src="${basePath}/layui/layui.js"></script>
</head>

<body class="page-body">
<div class="layui-inline"></div>
<div id="content">
    <form class="layui-form" action="" lay-filter="example">
        <input name="id" type="hidden" value="${id}" id="merchQrcode_id">


                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label l-lab-text">商家名称:</label>
                        <div class="layui-input-inline">
                            <input name="userName" id="userName_inputId" lay-verify="" placeholder="商家名称" autocomplete="true" class="layui-input"
                                   type="text">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label l-lab-text">二维码:</label>
                        <div class="layui-input-inline">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="car_logo_up">选择图片</button>
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="car_logo_img" width="50px">
                                    <p id="demoText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" id="myDiv" name="qrcode"/>
                    <%--<div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-warm layui-btn-disabled" id="logo_doup">上传</button>
                    </div>--%>
                </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label l-lab-text">状态:</label>
                            <div class="layui-input-inline">
                                <select name="status" id="status_selectId" lay-search="">
                                    <option value="" class="l-lab-text">All</option>
                                </select>
                            </div>
                        </div>
                    </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn l-lab-text" lay-submit lay-filter="formDemo">OK</button>
                <button class="layui-btn layui-btn-warm l-lab-text" onclick="top.layer.close(top.addMerchQrcode_layer)" >Cancel</button>
                <button type="reset" class="layui-btn layui-btn-primary l-lab-text">Rest</button>
            </div>
        </div>
    </form>
</div>
<div class="ibox-content">
    <table class="table-hide" id="demoTable" lay-data="{id: 'idApply'}" lay-filter="Apply"></table>
</div>
<script src="${basePath}/js/i18n.js"></script>
<script src="${basePath}/js/common.js"></script>
<script src="${basePath}/js/DateFormate.js"></script>
<script src="${basePath}/js/QiniuUpLoad.js"></script>
<script>
    $(function () {
        doTranslate();
        /*初始化下拉选*/
        var types=['merchQrcode_status'];
        //批量初始化下拉选
        initBatchSelect(types,function () {
            doSetEditFormData();
            initForm();
        });

        //文件上传
        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#car_logo_up'
                ,url: '${basePath}/upload/'
                ,auto: false
                ,choose: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#car_logo_img').attr('src', result); //图片链接（base64）
                        debugger
                        var token;
                        //获取七牛token
                        token = getUpToken(file.name);
                        // $('#logo_doup').removeClass('layui-btn-disabled').on('click',function () {
                        top.myLayer.msg("start upload");

                        putb64(result,token);//开始上传
                        // });
                    });
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });
    })
    function doSetEditFormData() {
        var id=$("#merchQrcode_id").val();
        if(id){
            $.post('${basePath}/server/merchQrcode/findMerchQrcodeOne.do',{id:id},function (result) {
                if(result&&result.code==0){
                    var data=result.data;
                   // debugger
                    layui.use('form', function(){
                        var form = layui.form;
                        //表单初始赋值
                        form.val('example', {
                            "userId": data.userId,
                            "userName": data.userName,
                            "qrcode": data.qrcode,
                            "status": data.status,
                            "createUser": data.createUser,
                            "createTime": data.createTime,
                            "updateUser": data.updateUser,
                            "updateTime": data.updateTime,
                        })
                        form.render();
                    });
                }else {
                    top.myLayer.confirm(top._loadText(result.msg));
                }
            })

        }
    }
    function initForm(){
        layui.use(['form','element'], function(){
            var form = layui.form;

            //监听提交
            form.on('submit(formDemo)', function(data){
                debugger
                // top.layer.msg(JSON.stringify(data.field));
                var id=data.field.id;
                var url=id?'${basePath}/server/merchQrcode/updateMerchQrcode.do':'${basePath}/server/merchQrcode/addMerchQrcode.do'
                $.post(url,data.field,function (result) {
                    if(result&&result.code==0){
                        top.myLayer.msg(top._loadText('Add successful'),null,top.layer.close(top.addMerchQrcode_layer));
                    }else{
                        top.myLayer.confirm(top._loadText('Add failed')+top._loadText(result.msg));
                    }
                })
                return false;
            });
        });
    }
</script>
</body>
</html>
